package Test;

import java.util.*;

public class Test14 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,3,2};
        Map<Integer,Integer> map = new HashMap<>();
        for(Integer x : arr){
            if(map.containsKey(x)){
                map.put(x,map.get(x)+1);
            }else{
                map.put(x,1);
            }
        }
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            System.out.println(entry.getKey()+"-->"+entry.getValue());
        }
    }
    public static void main2(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("hello");
        set.add("the");
        set.add("sunny");
        System.out.println(set);

        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
    public static void main1(String[] args) {
        TreeMap<String,Integer> map = new TreeMap<>();//查找复杂度为O（logN）
        map.put("sunny",3);
        map.put("the",5);
        map.put("hello",2);
        //比较大小是通过Key的值比较的
        //通过Key获取Value值
        Integer value = map.get("the");
        System.out.println(value);

        Integer val = map.getOrDefault("the2",9999999);
        System.out.println(val);

        Set<String> set = map.keySet();
        System.out.println(set);

        Collection<Integer> collection = map.values();
        System.out.println(collection);

        System.out.println("=======================");

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> entry:entrySet){
            System.out.println(entry.getKey()+"-->"+entry.getValue());
        }
    }
}
